package com.speedata.testsimple;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.serialport.DeviceControlSpd;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import com.speedata.uhftest.R;
import com.speedata.utils.ToastUtils;

import java.io.IOException;


/**
 * @author xu  T50-DB双路USB
 * @date 2023/02/14
 */

public class DoubleUsbT50dbAct extends AppCompatActivity implements View.OnClickListener {


    /**
     *
     */
    private Button bt2;
    private Button bt1;
    private DeviceControlSpd deviceControlSpd;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_doubleusbt50db);
        initView();
        try {
            deviceControlSpd = new DeviceControlSpd(DeviceControlSpd.POWER_NEWMAIN_FG);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }


    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    private void initView() {
        bt1 = findViewById(R.id.bt1);
        bt1.setOnClickListener(this);
        bt2 = findViewById(R.id.bt2);
        bt2.setOnClickListener(this);

    }

    @SuppressLint("NonConstantResourceId")
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt1:
                try {
                    deviceControlSpd.newFgSetGpioOn(175);
                    deviceControlSpd.newFgSetGpioOn(165);
                    deviceControlSpd.newFgSetGpioOn(156);
                    deviceControlSpd.newFgSetGpioOn(9);
                    ToastUtils.showShortToastSafe("175,165,156,9上电成功");
                } catch (IOException e) {
                    ToastUtils.showShortToastSafe("上电异常：" + e.getMessage());
                    e.printStackTrace();
                }
                break;
            case R.id.bt2:
                try {
                    deviceControlSpd.newFgSetGpioOff(9);
                    deviceControlSpd.newFgSetGpioOff(156);
                    deviceControlSpd.newFgSetGpioOff(165);
                    deviceControlSpd.newFgSetGpioOff(175);
                    ToastUtils.showShortToastSafe("9,156,165,175下电成功");
                } catch (IOException e) {
                    ToastUtils.showShortToastSafe("下电异常：" + e.getMessage());
                    e.printStackTrace();
                }
                break;
            default:
                break;
        }
    }
}
